var t = require("../../../@babel/runtime/helpers/typeof"), a = require("../../../@babel/runtime/helpers/defineProperty"), e = getApp();

Page({
    data: {
        activeName: "",
        step: 1,
        checkboxGroup: [],
        protocolShow: !1,
        agreement: {},
        form: {
            name: "",
            id_no: "",
            tel: "",
            captcha: "",
            face_auth_mode: "",
            invite_code: ""
        },
        authcode: "",
        bank_no: "",
        flow_id: "",
        count: "",
        timer: null,
        imgcode: "",
        is_real_name: !1,
        real_name_auth_set: {},
        shop_name: "",
        realNameProtocolShow: !1,
        is_bind_mobile: 0,
        is_mobile: 1
    },
    onLoad: function(t) {
        this.data.options = t, "bindRealName" === t.from ? (this.setData({
            is_real_name: !0
        }), this.getimgdata(), this.getAuth()) : (this.getPersonData(), this.getAgreement());
    },
    onReady: function() {},
    onShow: function() {
        "bindRealName" == this.data.options.from && this.checkPayStatus();
    },
    checkPayStatus: function() {
        var t = e.getNetAddresss("plugin.real-name-auth.frontend.pay.index");
        e._getNetWork({
            url: t,
            validateBol: 2,
            success: function(t) {
                var a = t.data;
                1 == a.result && (console.log(a, "ddddddddddd"), 1 == a.data.is_not_free && 0 == a.data.pay_status && wx.navigateTo({
                    url: "/packageD/buy/orderPay/orderPay?tag=auth&price=" + a.data.pay_amount
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    captchainp: function(t) {
        var a = t.detail.value;
        this.setData({
            "form.captcha": a.trim()
        });
    },
    getimgdata: function() {
        var t = this, a = e.getNetAddresss("home-page.getCaptcha");
        e._getNetWork({
            url: a,
            validateBol: 2,
            success: function(a) {
                var e = a.data;
                1 == e.result && e.data.captcha && t.setData({
                    imgcode: e.data.captcha.img
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getAuth: function() {
        var t = this, a = e.getNetAddresss("plugin.real-name-auth.frontend.auth.index");
        e._getNetWork({
            url: a,
            success: function(a) {
                var e = a.data;
                1 === e.result ? (e.data.protocol_set && e.data.protocol_set.content && (e.data.protocol_set.content = e.data.protocol_set.content.replace(/<img/gi, '<img style="max-width:100%;height:auto;display:block" '), 
                e.data.real_name_auth_set.content = e.data.real_name_auth_set.content.replace(/<img/gi, '<img style="max-width:100%;height:auto;display:block" ')), 
                t.setData({
                    real_name_auth_set: e.data.real_name_auth_set,
                    agreement: e.data.protocol_set,
                    shop_name: e.data.shop_name,
                    is_bind_mobile: e.data.is_bind_mobile
                }), e.data.relation && t.setData({
                    "form.invite_code": e.data.relation.invite_code
                })) : console.log(e.msg);
            },
            fail: function(t) {
                console.log(t, "失败-----------");
            }
        });
    },
    sureAuthIdentify: function() {
        var t = this, s = "", o = {};
        e._isTextEmpty(this.data.form.captcha) && this.data.imgcode ? wx.showToast({
            icon: "none",
            title: "请填写图形验证码",
            duration: 1500
        }) : (1 == this.data.activeName ? (s = e.getNetAddresss("plugin.real-name-auth.frontend.auth.authTel"), 
        o = this.data.form) : 2 == this.data.activeName && (s = e.getNetAddresss("plugin.real-name-auth.frontend.auth.authBank"), 
        this.setData(a({}, "form.bank_no", this.data.bank_no)), o = this.data.form), e._postNetWork({
            url: s,
            data: o,
            success: function(a) {
                if (t.data.timer = null, 1 === a.data.result) {
                    var s = a.data;
                    e.tips("已发送"), t.setData({
                        flow_id: s.data.flowId
                    }), t.data.timer || (t.countDown = 60, t.data.timer = setInterval(function() {
                        t.countDown > 0 && t.countDown <= 60 ? t.setData({
                            count: --t.countDown
                        }) : (clearInterval(t.data.timer), t.data.timer = null);
                    }, 1e3));
                } else wx.showModal({
                    title: "提示",
                    content: a.data.msg,
                    showCancel: !1
                });
            }
        }));
    },
    sendAuthCode: function() {
        var t = this, a = "", s = {};
        1 == this.data.activeName ? (a = e.getNetAddresss("plugin.real-name-auth.frontend.auth.telSms"), 
        s = {
            flow_id: this.data.flow_id,
            code: this.data.authcode
        }) : 2 == this.data.activeName ? (a = e.getNetAddresss("plugin.real-name-auth.frontend.auth.bankSms"), 
        s = {
            flow_id: this.data.flow_id,
            code: this.data.authcode
        }) : (a = e.getNetAddresss("plugin.real-name-auth.frontend.auth.authFace"), s = {
            name: this.data.form.name,
            id_no: this.data.form.id_no,
            tel: this.data.form.tel,
            face_auth_mode: 1 == this.data.form.face_auth_mode ? "ESIGN" : "",
            callback_url: "/packageG/index/index",
            invite_code: this.form.invite_code
        }), e._postNetWork({
            url: a,
            data: s,
            success: function(a) {
                var s, o = a.data;
                1 === o.result ? (s = t.data.real_name_auth_set.auth_scene.indexOf("1") > -1 ? wx.getStorageSync("yz_redirect") : wx.getStorageSync("real_name_redirect"), 
                3 == t.data.activeName ? (t.setData({
                    flow_id: o.data.flowId
                }), wx.navigateToMiniProgram({
                    appId: "wx1cf2708c2de46337",
                    path: "/pages/index/index",
                    extraData: {
                        requestObj: {
                            flowId: o.data.flowId,
                            type: "REALNAME",
                            env: "prod"
                        },
                        callbackObj: {
                            url: "/".concat(s)
                        },
                        envVersion: "release"
                    }
                }), wx.removeStorageSync("real_name_redirect")) : (e.tips("认证成功"), s ? (wx.redirectTo({
                    url: "/".concat(s),
                    fail: function(t) {
                        wx.reLaunch({
                            url: "/packageG/index/index"
                        });
                    }
                }), wx.removeStorageSync("real_name_redirect")) : wx.reLaunch({
                    url: "/packageG/index/index"
                }))) : wx.showModal({
                    title: "提示",
                    content: a.data.msg,
                    showCancel: !1
                });
            },
            fail: function(t) {
                e.tips(t.msg);
            }
        });
    },
    getPersonData: function() {
        var t = this, a = e.getNetAddresss("plugin.yun-sign.frontend.h5.person.check-person-approve");
        e._getNetWork({
            url: a,
            success: function(a) {
                var e = a.data;
                1 === e.result ? (t.setData({
                    person: e.data
                }), "SUCCESS" == e.status && wx.navigateTo({
                    url: "/packageH/signPage/identifyResult/identifyResult?show=person"
                })) : console.log(e.msg);
            },
            fail: function(t) {
                console.log(t, "失败-----------");
            }
        });
    },
    getAgreement: function() {
        var t = this, a = e.getNetAddresss("plugin.yun-sign.frontend.person.get-agreement");
        e._postNetWork({
            url: a,
            showToastIn: !0,
            success: function(a) {
                var s = a.data;
                1 === s.result ? t.setData({
                    agreement: s.data
                }) : e.tips(s.msg);
            }
        });
    },
    getMemberData: function() {
        var t = this;
        if (!(this.data.checkboxGroup.length <= 0) || this.data.is_real_name && 1 != this.data.agreement.status) if (this.data.is_real_name) this.setData({
            step: 2
        }); else if (this.data.checkboxGroup.length < 1) wx.showModal({
            content: "请先同意并勾选协议",
            showCancel: !1
        }); else {
            var s = e.getNetAddresss("plugin.yun-sign.frontend.h5.person.get-person-auth-info");
            e._postNetWork({
                url: s,
                success: function(s) {
                    t.setData({
                        step: 2
                    });
                    var o, n = s.data;
                    1 === n.result ? t.setData((a(o = {}, "form.name", s.data.name), a(o, "form.tel", s.data.tel), 
                    o)) : e.tips(n.msg);
                },
                fail: function(t) {
                    console.log(t, "失败-----------");
                }
            });
        }
    },
    toStep: function() {
        this.data.form.name ? this.data.form.id_no ? this.data.form.tel ? this.data.activeName && (1 != this.data.real_name_auth_set.must_invite_code || this.data.form.invite_code) ? this.data.is_real_name ? this.setData({
            step: 3
        }) : this.checkPersonData() : e.tips("请先选择认证方式") : e.tips("请先填写手机号") : e.tips("请先填写身份证号") : e.tips("请先填写姓名");
    },
    checkPersonData: function() {
        var t = this, a = e.getNetAddresss("plugin.yun-sign.frontend.person.check-person-approve-by-idNo");
        e._getNetWork({
            url: a,
            showToastIn: !0,
            data: {
                name: this.data.form.name,
                idNo: this.data.form.id_no,
                tel: this.data.form.tel
            },
            success: function(a) {
                if (1 === a.data.result) {
                    var e = a.data;
                    t.setData({
                        person: e.data
                    }), 99 == e.data.status_code ? wx.showModal({
                        title: "提示",
                        content: "您在认证中心已经完成认证，无需重复认证",
                        showCancel: !1,
                        success: function() {
                            wx.navigateTo({
                                url: "/packageH/signPage/identifyResult/identifyResult?show=person"
                            });
                        }
                    }) : t.setData({
                        step: 3
                    });
                } else wx.showModal({
                    content: a.data.msg,
                    showCancel: !1
                });
            },
            fail: function(t) {
                console.log(t, "失败-----------");
            }
        });
    },
    sureIdentify: function() {
        var t = this;
        if (2 != this.data.activeName || this.data.bank_no) if (this.data.is_real_name) this.sureAuthIdentify(); else {
            var s = "", o = {};
            1 == this.data.activeName ? (s = e.getNetAddresss("plugin.yun-sign.frontend.h5.person.auth-tel-v2"), 
            o = this.data.form) : 2 == this.data.activeName && (s = e.getNetAddresss("plugin.yun-sign.frontend.h5.person.auth-bank-card-v2"), 
            this.setData(a({}, "form.bank_no", this.data.bank_no)), o = this.data.form), e._postNetWork({
                url: s,
                data: o,
                success: function(a) {
                    if (t.data.timer = null, 1 === a.data.result) {
                        var s = a.data;
                        e.tips("已发送"), t.setData({
                            flow_id: s.data.data.flowId
                        }), t.data.timer || (t.countDown = 60, t.data.timer = setInterval(function() {
                            t.countDown > 0 && t.countDown <= 60 ? t.setData({
                                count: --t.countDown
                            }) : (clearInterval(t.data.timer), t.data.timer = null);
                        }, 1e3));
                    } else wx.showModal({
                        title: "提示",
                        content: a.data.msg,
                        showCancel: !1
                    });
                }
            });
        } else e.tips("请先填写银行卡");
    },
    sendCode: function() {
        if (2 != this.data.activeName || this.data.bank_no) if (3 == this.data.activeName || this.data.flow_id) {
            if (console.log(this.data.authcode), 3 == this.data.activeName || this.data.authcode) return 3 != this.data.activeName || this.data.form.face_auth_mode ? void (this.data.is_real_name ? this.sendAuthCode() : this.sendAuthRequest()) : (console.log(t(this.data.activeName), this.data.form), 
            void e.tips("请先选择识别方式"));
            e.tips("请先填写验证码");
        } else e.tips("请先获取验证码"); else e.tips("请先填写银行卡");
    },
    sendAuthRequest: function() {
        var t = this, a = "", s = {};
        1 == this.data.activeName ? (a = e.getNetAddresss("plugin.yun-sign.frontend.person.check-tel-sms-code"), 
        s = {
            flow_id: this.data.flow_id,
            authcode: this.data.authcode
        }) : 2 == this.data.activeName ? (a = e.getNetAddresss("plugin.yun-sign.frontend.person.check-bank-sms-code"), 
        s = {
            flow_id: this.data.flow_id,
            authcode: this.data.authcode
        }) : (a = e.getNetAddresss("plugin.yun-sign.frontend.h5.person.auth-face-v2"), s = {
            name: this.data.form.name,
            id_no: this.data.form.id_no,
            tel: this.data.form.tel,
            face_auth_mode: this.data.form.face_auth_mode,
            callback_url: ""
        }), e._postNetWork({
            url: a,
            data: s,
            success: function(a) {
                var s = a.data;
                1 === s.result ? 3 == t.data.activeName ? wx.redirectTo({
                    url: "/packageH/signPage/signPage?url=".concat(s.data.data.authUrl)
                }) : (e.tips(s.msg), wx.redirectTo({
                    url: "/packageH/signPage/identifyResult/identifyResult?show=person"
                })) : wx.showModal({
                    title: "提示",
                    content: a.data.msg,
                    showCancel: !1
                });
            },
            fail: function(t) {
                e.tips(t.msg);
            }
        });
    },
    onAgree: function(t) {
        this.setData({
            checkboxGroup: t.detail
        });
    },
    showProtocol: function() {
        this.setData({
            protocolShow: !0
        });
    },
    showAuthProtocol: function() {
        this.setData({
            realNameProtocolShow: !0
        });
    },
    closePopup: function() {
        this.setData({
            protocolShow: !1,
            realNameProtocolShow: !1
        });
    },
    handlerInput: function(t) {
        var e = t.target.dataset.type;
        this.setData(a({}, "".concat(e), t.detail));
    },
    onHide: function() {
        clearInterval(this.data.timer);
    }
});